import 'package:flutter/material.dart';
import 'package:fultter/config/them_config.dart';

import 'config/provide_config.dart';

void main() => runApp(ProvideConfig.init(child: MyThemApp()));

class MyThemApp extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return ProvideConfig.connet<ThemConfigModel>(builder: (context,child,ThemConfigModel model){
      return  MaterialApp(
          theme: model.defaultTheme,
          home: MyhomePage(),
      );
    });

      MaterialApp(home: MyhomePage(),);
  }
}

class MyhomePage extends StatefulWidget {
  const MyhomePage({Key key,this.title}) : super(key: key);
  final String title;

  @override
  _MyhomePageState createState() => _MyhomePageState();
}

class _MyhomePageState extends State<MyhomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("应用切换主题"),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            FlatButton(
                onPressed: (){
                  ProvideConfig.value<ThemConfigModel>(context).setThem(0);
                },
                child: Text("亮色")),
            FlatButton(
                onPressed: (){
                  ProvideConfig.value<ThemConfigModel>(context).setThem(1);
                },
                child: Text("暗色")),
            FlatButton(
                onPressed: (){
                  ProvideConfig.value<ThemConfigModel>(context).setThem(2);
                },
                child: Text("紫色")
            ),
          ],
        ),
      ),
    );
  }
}

